function getStyle(obj, attr) {
    if (window.getComputedStyle) {
        return window.getComputedStyle(obj, null)[attr];
    }
    return obj.currentStyle[attr];
}

function animate(oEle, json, callback) {
    //1.清除之前的定时器
    clearInterval(oEle.timer)
    //2.开始定时器
    oEle.timer = setInterval(() => {
        let target; //目标位置
        let current; //当前位置
        let flag = true;
        for (let attr in json) {
            if (attr == "opacity") {
                target = json[attr] * 100;
                current = getStyle(oEle, attr) * 100
            } else {
                target = parseInt(json[attr]);
                current = parseInt(getStyle(oEle, attr))
            }
            //步长=(目标位置-当前位置)/10
            let step = (target - current) / 10;
            step = step > 0 ? Math.ceil(step) : Math.floor(step);
            // 新的位置=当前位置+步长;
            if (attr == "opacity") {
                oEle.style.opacity = (current + step) / 100
            } else if (attr == "zIndex") {
                oEle.style.zIndex = target;
            } else {
                oEle.style[attr] = current + step + "px";
            }
            if (current != target) {
                flag = false;
            }
        }
        if (flag) {
            clearInterval(oEle.timer);
            if (typeof (callback) == "function") {
                callback();
            }
        }
    }, 40);

}